package com.antd.common.data.mybatis;

import com.antd.common.auth.util.AntdSecurityUtil;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @author 子丶沫
 * @date 2021-06-09 15:55
 */
@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "createTime", LocalDateTime.class,LocalDateTime.now());
        this.strictInsertFill(metaObject,"createBy",String.class,AntdSecurityUtil.getUser().getUserId());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "updateTime", LocalDateTime.class,LocalDateTime.now());
        this.strictInsertFill(metaObject,"updateBy",String.class,AntdSecurityUtil.getUser().getUserId());
    }
}
